package com.wica.view.tab_preference;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.widget.Toast;

import com.wica.facetube.R;

public class TabPreferencesMostViewed extends TabPreferences {
	
	// *************** Constants ************** //  
    public static final String MOST_VIEWED_TAB_PREFERENCES_1 = "most_viewed_time";
    public static final String MOST_VIEWED_TAB_PREFERENCES_2= "most_viewed_numberOfResults";
    public static final int MAX_NUMBEROFRESULTS=50;
	// Log constant
	public static final String LOG_TAG = "__FT.TabPreferencesMostViewed__";

	// *************** Methods **************************** //
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.most_viewed_preferences);    
    }// onCreate method
    
	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		if (key.equals(MOST_VIEWED_TAB_PREFERENCES_1)) {
            Toast.makeText(this, sharedPreferences.getString(key, "Default ")+" search will be performed.", Toast.LENGTH_SHORT).show();
    		finish();
        }else if (key.equals(MOST_VIEWED_TAB_PREFERENCES_2)) {
        	Integer integer = new Integer(sharedPreferences.getString(key, "0"));
        	int i = integer.intValue();
        	if (i<MAX_NUMBEROFRESULTS){
        		Toast.makeText(this, sharedPreferences.getString(key, "0")+" results will be shown.", Toast.LENGTH_SHORT).show();
        		finish();
        	}else if (i==MAX_NUMBEROFRESULTS){
        		Toast.makeText(this, "The maximum number of results ("+MAX_NUMBEROFRESULTS+") will be shown.", Toast.LENGTH_SHORT).show();
        		finish();
        	}else{
        		Editor s = sharedPreferences.edit();        		
        		s.putString(key, MAX_NUMBEROFRESULTS+"");        		
        		s.commit();
        	}            
        }		
	}// onSharedPreferenceChanged method
	
}// TabPreferencesMostViewed class